#include<stdio.h>
typedef struct birth
{
    int year;
    int month;
    int day;
}birth;
void fread_fwrite(void);
void strnct_fread_fwrite(void);
int main(int argc, char const *argv[])
{
    fread_fwrite();
    strnct_fread_fwrite();
    return 0;
}
void fread_fwrite(void)
{
    FILE *fp;
    fp=fopen("text1","w+");
    if(!fp)
    {
        printf("文件打开失败");
        return ;
    }
    int num[5]={1,2,3,4,5},arr[5]={0};
    fwrite(num,sizeof(int),5,fp);
    rewind(fp);
    fread(arr,sizeof(int),5,fp);
    for (int i = 0; i < 5; i++)
    {
       printf("%d\t",arr[i]);
    }
    
}
void strnct_fread_fwrite(void)
{
    FILE *fp;
    fp=fopen("text2","w+");
    if(!fp)
    {
        printf("文件打开失败");
        return ;
    }
    birth b;
    birth my={2004,9,18};
    fwrite(&my,sizeof(birth),1,fp);
    rewind(fp);
    fread(&b,sizeof(birth),1,fp);
    printf("%d %d %d",b.year,b.month,b.day);
}